import { Command } from '../command.js';
import { BoxGeometry, Group, Light, Mesh, MeshBasicMaterial, Object3D, ObjectLoader, SphereGeometry } from 'three';
import { Editor } from '../editor.js';
import { CSS3DObject } from 'three/examples/jsm/renderers/CSS3DRenderer.js';

/**
 * @param editor Editor
 * @param object THREE.Object3D
 * @constructor
 */
class AddObjectCommand extends Command {
	object:Object3D;
	constructor( editor:Editor, object:Object3D ) {

		super( editor );

		this.type = 'AddObjectCommand';

		this.object = object;
		
		if ( object !== undefined ) {

			this.name = `Add Object: ${object.name}`;

		}

	}

	execute() {
		if(this.object instanceof Light){
			// 灯光
			const lightHelperGeometry = new SphereGeometry(0.5, 16, 16);
			const lightHelperMaterial = new MeshBasicMaterial({ 
				color: 0xffff00,
				visible: false // 设置为不可见，只用于检测
			});
			const lightHelper = new Mesh(lightHelperGeometry, lightHelperMaterial);
			lightHelper.name = '!__lightHelper';
			this.object.add(lightHelper); // 将辅助球体作为灯光的子对象
		}
		this.editor.addObject( this.object );
		
		this.editor.select( this.object );

	}

	undo() {

		this.editor.removeObject( this.object );
		this.editor.deselect();

	}

}

export { AddObjectCommand };
